﻿#include <libcomm.h>

int main(int argc, char *argv[])
{
	JsonRoot root;
	// add sub object item.
	String a;
	root["name"] = a;//"wanghh";
	root.Add("tt", a);
	root.Add("name2", "redrat");
	root["age"] = 0.327;//18.5;

	// add 2-level sub object item.
	root["test"]["item1"] = 1;
	root["test"]["item2"] = "2";

	// add sub array item.
	root["city"].Add("bj");
	root.AddArray("city").Add("wh");
	root["city"].Insert(1, 0.327);
	root["city"].Add(2);

	// add 2-level sub array item.
	root("area")[0].Add(100);
	root("area")[0].Add(200);
	root.AddArray("area")[0].Add(500);
	root("area")[1].Add(200);
	root("area")[2].Add(400);
	root("area")[3].Add("a", 5);
	root("area")[3].Add("b", 6);
	root("area").Remove(2);
	

	printf("=================:\n%s\n=================\n", root.ToJson(true).get());
	printf("city[0] = \"%s\"\n", root["city"][0].AsString().get());
	printf("city[1] = %.3f\n", root["city"][1].AsNumber());
	printf("city[2] = \"%s\"\n", root["city"][2].AsString().get());
	printf("city[3] = %d\n", root["city"][3].AsInt());

	MYLIB_JSON2CV(root, String, name2, "");
	printf("name2: %s\n", name2.get());

	return 0;
}

/*
console out:
=================:
{
"name": "wanghh",
"name2":        "redrat",
"age":  0.327,
"test": {
	"item1":        1,
	"item2":        "2"
},
"city": ["bj", 0.327, "wh", 2],
"area": [[100, 200, 500], [200], {"a": 5, "b": 6}]
}
=================
city[0] = "bj"
city[1] = 0.327
city[2] = "wh"
city[3] = 2
name2: redrat

*/
